/*
 * @Description: 登录模块
 * @Version: 1.0
 * @Author: yxx
 * @Date: 2023-09-20 16:12:34
 * @LastEditors: yxx
 * @LastEditTime: 2025-05-26 16:35:05
 */
import { LoginSpace } from "@/api/interface/login"
import http from "@/api"

// ------------------登录模块------------------ //
// 登录模块 获取验证码
export const getCodeApi = () => {
  return http.get<LoginSpace.CodeInfo>("/sys/code", {}, { loading: false })
}
// 登录模块 用户登录
export const loginApi = (params: LoginSpace.Login) => {
  return http.post<LoginSpace.UserInfo>("/sys/login", params, { loading: true }) // 正常 post json 请求  ==>  application/json
  // return http.post<Login.ResLogin>(PORT1 + `/login`, params, { loading: false }); // 控制当前请求不显示 loading
  // return http.post<Login.ResLogin>(PORT1 + `/login`, {}, { params }); // post 请求携带 query 参数  ==>  ?username=admin&password=123456
  // return http.post<Login.ResLogin>(PORT1 + `/login`, qs.stringify(params)); // post 请求携带表单参数  ==>  application/x-www-form-urlencoded
  // return http.get<Login.ResLogin>(PORT1 + `/login?${qs.stringify(params, { arrayFormat: "repeat" })}`); // get 请求可以携带数组等复杂参数
}
// 登录模块 获取菜单按钮列表
export const getPermsApi = () => {
  return http.get<LoginSpace.UserPermissions>("/sys/login/perms", {}, { loading: true })
}
// 登录模块 退出登录
export const logoutApi = () => {
  return http.get("/sys/logout")
}
// 登录模块 修改密码
export const modifyPasswordApi = (params: LoginSpace.ModifyPassword, token?: string) => {
  return http.post("/sys/login/modify/pwd", params, { loading: false, token })
}
